// 关于 用户 的路由

const express = require('express');

const router = express.Router();

// 执行函数
const userHandler = require('../router_handler/user_handler');
const categoryHandler = require('../router_handler/category_handler');
// 执行函数
const articleHandler = require('../router_handler/article_handler');
const {articlePage_schema,articleDetail_schema} = require('../schema/article_schema')
// 校验
const {comment_page_articleId} =require('../schema/comment_schema')
// 校验
const {reply_page_commentId} =require('../schema/reply_schema')
// 执行函数
const replyHandle = require('../router_handler/reply_handler');
// 数据校验
const expressJoi = require('@escook/express-joi');
const userSchema = require('../schema/user_schema');
// 执行函数
const commentHandle = require('../router_handler/comment_handler');
const { sqlOne } = require('../db/common');
const Joi = require('joi');
// 登录路由
router.post('/login', expressJoi(userSchema.login_schema),userHandler.login);
// 注册路由
router.post('/register', expressJoi(userSchema.reg_schema),userHandler.register);
router.get('/emailCode', expressJoi({query:{email:Joi.string().email().required()}}),userHandler.emailCode);



// 获取分类
router.get('/category',categoryHandler.getCategory);

// 获取文章
router.post('/article' ,expressJoi(articlePage_schema),articleHandler.getArticlePage);

// 获取文章详情
router.get('/articleDetail' ,expressJoi(articleDetail_schema),articleHandler.getArticleDetail);
router.get('/comment' ,expressJoi(comment_page_articleId) ,commentHandle.getArticleComment);

// =====   评论回复  ======
router.get('/reply',expressJoi(reply_page_commentId),replyHandle.getCommentReply);


// 获取首页轮播图
router.get('/main',async (req,res)=>{
    const sql = `select id,image,title,url from t_carousel where deletedAt is NULL`
    const data = await sqlOne(sql)
    res.onSuccess(data)
})


// 导出路由
module.exports = router;